<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    :title="getTitle"
    @ok="handleSubmit"
    :minHeight="100"
  >
    <FilterConditions
      @success="handleSuccess"
      :headStyle="headStyle"
      :formGetFieldsData="formGetFieldsData"
      :filterCond="filterCond"
      :mainId="mainId"
      :filterUnitCode="filterUnitCode"
    />
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, computed } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import {} from 'ant-design-vue';
  import FilterConditions from './filterConditions/index.vue';
  import { headStyle } from '/@/views/pages/managerPage/managerPage.data';
  import { getFormGetFields } from '/@/api/flowManage/flowManage';

  export default defineComponent({
    components: { BasicModal, FilterConditions },
    emits: ['success', 'register'],
    setup(_, { emit }) {
      let isUpdate = ref(true);
      let dataRef = ref<Recordable>({});
      const filterCond = ref('');
      const formCode = ref('');
      const mainId = ref('');
      const filterUnitCode = ref(0);

      const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
        setModalProps({ confirmLoading: false, width: '1000px', showOkBtn: false });
        isUpdate.value = !!data?.isUpdate;
        filterCond.value = data?.filterCond;
        formCode.value = data?.formCode;
        mainId.value = data?.mainId;
        filterUnitCode.value = data?.filterUnitCode;
        console.log('data', data);
        getFormGetFieldsData();
      });

      const getTitle = computed(() => '配置');

      async function handleSubmit() {
        // try {
        //   setModalProps({ confirmLoading: true });
        //   const formData = Object.assign({}, dataRef.value);
        //   closeModal();
        //   emit('success');
        // } finally {
        //   setModalProps({ confirmLoading: false });
        // }
      }

      const handleSuccess = () => {
        closeModal();
        emit('success');
      };

      const formGetFieldsData = ref([]);
      //获取数据
      const getFormGetFieldsData = () => {
        formGetFieldsData.value = [];
        try {
          if (!formCode.value) return;
          getFormGetFields({ formCode: formCode.value }).then((res) => {
            formGetFieldsData.value = res || [];
            formGetFieldsData.value.forEach((item: Recordable) => {
              delete item.options;
              item.value = item.name;
              item.label = item.title;
            });
          });
        } catch (err) {
          console.error('getFormGetFields', err);
        }
      };
      return {
        registerModal,
        getTitle,
        handleSubmit,
        handleSuccess,
        formCode,
        headStyle,
        formGetFieldsData,
        filterCond,
        mainId,
        filterUnitCode,
      };
    },
  });</script
>./FilterModal.vue
